package com.bjsxt;

import java.util.Objects;

public class Users implements Comparable<Users> {

        private String usersName;
        private int usersAge;

        public Users(String usersName, int usersAge) {
            this.usersName = usersName;
            this.usersAge = usersAge;
        }

        public Users() {
        }

        public String getUsersName() {
            return usersName;
        }

        public void setUsersName(String usersName) {
            this.usersName = usersName;
        }

        public int getUsersAge() {
            return usersAge;
        }

        public void setUsersAge(int usersAge) {
            this.usersAge = usersAge;
        }

        @Override
        public String toString() {
            return "Users{" +
                    "usersName='" + usersName + '\'' +
                    ", usersAge=" + usersAge +
                    '}';
        }
        //从写hashcode与equal()
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            com.bjsxt.Users users = (com.bjsxt.Users) o;
            return usersAge == users.usersAge && Objects.equals(usersName, users.usersName);
        }

        @Override
        public int hashCode() {
            return Objects.hash(usersName, usersAge);
        }
    //定义规则  正数：大，负数：小，0：相等
    @Override
    public int compareTo(Users o) {
        //用年龄排序
        //  当前对象          传过来的对象
        if(this.usersAge>o.getUsersAge()){
            return 1;
        }
        if(this.usersAge==o.getUsersAge()){
            //String类本身就有compareTO方法，直接调用
          return this.usersName.compareTo(o.getUsersName());
        }
        return -1;
    }
}
